package com.tool.service;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tool.entity.User;
import com.tool.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author niuyicong
 * @date 2024/11/8  23:39:41
 * @description
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>
        implements UserService{

    @Autowired
    private UserMapper userMapper;

    public List<User> allUser(){
        List<User> users = userMapper.selectList(null);
        return users;
    }

    public User getUserById(Long userId){
        User user = userMapper.selectById(userId);
        return user;
    }

    public List<User> getUserByIds(List<Long> ids){
        List<User> user = this.listByIds(ids);
        return user;
    }

    public void update(User user){
        user.setAge(100);
        UpdateWrapper<User> wrapper = new UpdateWrapper<>();
        userMapper.update(user,wrapper);
    }

    public void insert(User user){
        userMapper.insert(user);
    }

    public void batchInsert(List<User> list){
        this.saveBatch(list);
    }

    public void delete(Long userId){
        userMapper.deleteById(userId);
    }

    public void batchDelete(List<Long> ids){
        this.removeBatchByIds(ids);
    }

}
